{
    let EVENT_CLICK = Laya.Event.CLICK;
    /**
     * 0:夺宝模式, 1:攻防模式, 2:赏金模式, 3:占点模式, 4:足球模式
     */
    let GAME_MODE_MAP = {
        "1" : 2,
        "2" : 1,
        "3" : 0,
        "4" : 3,
        "5" : 4
    };

    class GameMode extends ui.Match.GameModeUI {
        constructor (callback) {
            super();
            
            this.callback = callback;
            this.actions = null;

            this.init();
        }

        destroy () {
            super.destroy();
            Sail.io.unregister("chooseBattleMode", this.update);
        }

        init () {
            this.anchorX = 0.5;
            this.centerX = 0;
            this.initEvent();

            this.titleBG.index = CUR_SELECTED_MODE_BG;

            Sail.io.register("chooseBattleMode", this, this.update);
        }

        initEvent () {
            this.btnPVP.on(EVENT_CLICK, this, this.selectRole, ["pvp"]);
            this.btnPVE.on(EVENT_CLICK, this, this.selectRole, ["pve"]);
        }

        selectRole (type) {
            this.callback && this.callback(type);
        }

        update (data) {
            this.gameMode.index = GAME_MODE_MAP[data.mode];
            this.mapName.text = data.name;
            this.award.text = data.count;
            this.counter.text = data.time;
            this.collectProgress.scrollRect = {x : 0, y : 0, width : this.collectProgress.width * data.produce / data.total, height : this.collectProgress.height};
            this.gameIntro.text = data.desc;

            if(!data.firstWin){
                this.awardWrap.visible = true;
            }
            this.collectProgress.visible = true;
        }

        resize (width, height, rate){
            this.scale(rate, rate);
            this.top = 90 * rate;
        }
    }

    Sail.class(GameMode, "Com.Match.GameMode");
}